import hashlib
import openpyxl

# todo 改成自己的
operatorId = "123456"
fileName = '/Users/kent/Downloads/恒大充电通对接振轩南（UAT生产环境）.xlsx'

secretKinds = ["OperatorSecret", "SigSecret", "DataSecret", "DataSecretIV"]

def writeSecret(env):
    # 列表用来储存秘钥
    secretList = []

    for secretKind in secretKinds:
        rawStr = env + operatorId + secretKind

        # MD5加密
        md = hashlib.md5()
        md.update(rawStr.encode(encoding="utf8"))
        md = md.hexdigest()
        md = md[8:24].upper()

        secretList.append(md)

    # 将秘钥写入Excel文件

    xfile = openpyxl.load_workbook(fileName)
    sheet = xfile['Sheet1']
    for i in range(4):
        # todo 注意单元格坐标和表格对应
        sheet[f'C{i + 22}'] = secretList[i]
    xfile.save(fileName)


# todo 根据UAT还是DEV修改
writeSecret("UAT")
